package com.socool.sinofaith.adapter;

import java.util.ArrayList;

import com.socool.sinofaith.R;
import com.socool.sinofaith.model.QuestionAnswerBean;
import com.socool.sinofaith.model.TaskQuestionBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class QuestionTaskAdapter extends BaseAdapter {

	private Context context;
	private LayoutInflater inflater;
	private ArrayList<TaskQuestionBean> beans;

	public QuestionTaskAdapter(Context context) {
		this.context = context;
		inflater = LayoutInflater.from(context);
		beans = new ArrayList<TaskQuestionBean>();
	}

	public void setDatas(ArrayList<TaskQuestionBean> beans) {
		beans.clear();
		this.beans = beans;
		this.notifyDataSetChanged();
	}

	public void addDatas(ArrayList<TaskQuestionBean> beans) {
		this.beans.addAll(beans);
		this.notifyDataSetChanged();
	}

	public ArrayList<TaskQuestionBean> getDatas() {
		return this.beans;
	}

	@Override
	public int getCount() {
		return beans.size();
	}

	@Override
	public Object getItem(int position) {
		return beans.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_question, null);
			holder.tv_name = (TextView) convertView
					.findViewById(R.id.tv_name_question_item);
			holder.tv_date = (TextView) convertView
					.findViewById(R.id.tv_date_question_item);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		TaskQuestionBean bean = beans.get(position);
		holder.tv_name.setText(bean.getTaskName());
		holder.tv_date.setText(bean.getTaskDate());

		return convertView;
	}

	private class ViewHolder {
		TextView tv_name;
		TextView tv_date;
	}

}
